package lab4;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(name = "HitCountServlet", value = "/HitCountServlet")
public class HitCountServlet extends HttpServlet{
    @Override
    public void init() throws ServletException {
        super.init();
    }
    private static int cookieCount=0;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name="Cookie"+(++cookieCount);
        String value=String.valueOf(System.currentTimeMillis());
        response.setContentType("text/html; charset=utf-8");
        Cookie cookie=new Cookie(name,value);
        response.addCookie(cookie);
        response.getWriter().println("<center><h1>Total Number of Hits</h1>");
        response.getWriter().println(cookieCount);
        response.getWriter().println("</center>");
    }
}




